import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

// 静态路由模块（即所有用户都可以访问的页面）
import home from './modules/home'
import login from './modules/login'
import notFound from './modules/not_found'

export const constantRoutes = [
  home,
  login,
  notFound
]

// 动态路由模块（即所有用户都可以访问的页面）
import config from './modules/config'
import recharge_order from './modules/recharge_order'
import agent_cash_out from './modules/agent_cash_out'
import admin_user from './modules/admin_user'
import feedback from './modules/feedback'
import agent_user from './modules/agent_user'
import user from './modules/user'
import order from './modules/order'
import auth from './modules/admin_auth'
export const variableRoutes = [
  config,
  recharge_order,
  agent_cash_out,
  feedback,
  admin_user,
  agent_user,
  order,
  user,
  auth
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: [
    {
      path: '/',
      redirect: '/home'
    },
    ...constantRoutes
  ]
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
